//
//  VipPrivCommentCell.swift
//  XiaoJingMallSwift
//
//  Created by beisheng03 on 2017/8/10.
//  Copyright © 2017年 beisheng. All rights reserved.
//

import UIKit

protocol VipPrivCommentCellDeleage : NSObjectProtocol {
    
    func rightBtnDidTap(str: String)
    
}

class VipPrivCommentCell: BaseTableViewCell {
    
    @IBOutlet weak var topLabel: UILabel!
    
    @IBOutlet weak var litleImageView: UIImageView!
    
    weak var delegate : VipPrivCommentCellDeleage?

    @IBOutlet weak var leftImageView: UIImageView!
    
    @IBOutlet weak var topBgViewH: NSLayoutConstraint!
    @IBOutlet weak var middleLabel: UILabel!
    
    @IBOutlet weak var bottomLabel: UILabel!
    
    @IBOutlet weak var btn: UIButton!
    
    var index : IndexPath? {
    
        didSet{
            
            if index == nil {
                return
            }
            
            
            switch index!.row {
            case 1:
                leftImageView.image = UIImage(named: "vip02")
                middleLabel.text = "邀请好友注册"
                topBgViewH.constant = 62
                topLabel.text = "会员福利"
                btn.setTitle("立即邀请", for: .normal)

            case 2:
                leftImageView.image = UIImage(named: "vip04")
                middleLabel.text = "每日签到"
                topBgViewH.constant = 0
                topLabel.text = nil
            default:
                leftImageView.image = UIImage(named: "vip05")
                middleLabel.text = "身份实名认证"
                topBgViewH.constant = 0
                topLabel.text = nil
            }
        
        
        }
    
    
    }
    
    var model : VipPrivilegeModel?{
        
        didSet{
            
            if model == nil {
                return
            }
            
            switch index!.row {
            case 1:
                bottomLabel.text = "奖励\(model!.invite_bean)小鲸豆"
             case 2:
                bottomLabel.text = "奖励\(model!.signin_bean)小鲸豆"
                
                if model!.can_signin == "1" {
                    btn.isEnabled = true
                    btn.setTitle("马上签到", for: .normal)
                    btn.backgroundColor = UIColor.colorWith(r: 238, g: 61, b: 32)
                } else {
                    btn.isEnabled = false
                    btn.setTitle("已签到", for: .normal)
                    btn.backgroundColor = UIColor.colorWith(r: 142, g: 143, b: 144)
                    
                }

              default:
                bottomLabel.text = "奖励\(model!.authentic_gold)小鲸豆"

                if model!.can_authentic == "1" {
                    btn.isEnabled = true
                    btn.setTitle("去认证", for: .normal)
                    btn.backgroundColor = UIColor.colorWith(r: 238, g: 61, b: 32)
                } else {
                    btn.isEnabled = false
                    btn.setTitle("已认证", for: .normal)
                    btn.backgroundColor = UIColor.colorWith(r: 142, g: 143, b: 144)
                    
                }

            
            }
 
            
        }
        
        
    }

    

    override func awakeFromNib() {
        super.awakeFromNib()
        contentView.backgroundColor = UIColor.white
        btn.addCornerAndBorder(borderColor: nil, borderWidth: 0, masksToBounds: true, cornerRadius: 15)
        bottomLabel.textColor = UIColor.dakGray()

        litleImageView.image = UIImage(named: "vip03")

    }
    
    
    @IBAction func btnDidTap(_ sender: UIButton) {
        let temp = sender.currentTitle ?? ""
        
        switch temp {
        case "立即邀请":
            delegate?.rightBtnDidTap(str: "立即邀请")
        case "马上签到":
            delegate?.rightBtnDidTap(str: "马上签到")
        case "去认证":
            let temp = BaseViewController()
            temp.navigationItem.title = "实名认证"
            viewController().navigationController?.pushViewController(temp, animated: true)
        default:
            QLPlusLine()
        }
        
        
    }
    
    
    
    
    
    
    
    
    

    override func setSelected(_ selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }
    
}
